package Package.Example.GetsTheConstructorAndUses;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class GetsTheConstructorAndUsess {
    public static final void GetsTheConstructorAndUsess() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//        过反射获取公共的构造方法并创建对象
        Class <?> c=Class.forName("Package.Example.GetsTheConstructorAndUses.Student");
        Constructor<?> con=c.getConstructor(String.class,int.class,String.class);
        Object obj=con.newInstance("林青霞", 30, "西安");
        Student stu= (Student) obj;
        System.out.println(stu);
    }
}
